package io.renren.modules.generator.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.controller.BaseController;
import io.renren.modules.generator.entity.EnterpriseEvaluateEntity;
import io.renren.modules.generator.service.EnterpriseEvaluateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;



/**
 * 企业服务档案
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-09-22 15:49:20
 */
@RestController
@RequestMapping("generator/enterpriseevaluate")
@Api("企业信用评价接口")
public class EnterpriseEvaluateController extends BaseController {
    @Autowired
    private EnterpriseEvaluateService enterpriseEvaluateService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ApiOperation("分页列表")
    public R list(@RequestParam Map<String, Object> params,@RequestBody(required = false) EnterpriseEvaluateEntity enterpriseEvaluateEntity){
        if (enterpriseEvaluateEntity == null) {
            enterpriseEvaluateEntity = new EnterpriseEvaluateEntity();
        }
        enterpriseEvaluateEntity.setDeptId(getDeptId());
        PageUtils page = enterpriseEvaluateService.queryPage(params,enterpriseEvaluateEntity);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ApiOperation("根据id获取实体")
    public R info(@PathVariable("id") Integer id){
		EnterpriseEvaluateEntity enterpriseEvaluate = enterpriseEvaluateService.getById(id);

        return R.ok().put("enterpriseEvaluate", enterpriseEvaluate);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ApiOperation("保存")
    public R save(@RequestBody EnterpriseEvaluateEntity enterpriseEvaluate){
        enterpriseEvaluate.setCreateTime(new Date());
        enterpriseEvaluate.setCreateUserId(getUserId());
        enterpriseEvaluate.setCreateUserName(getUserName());
        enterpriseEvaluateService.save(enterpriseEvaluate);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ApiOperation("更新")
    public R update(@RequestBody EnterpriseEvaluateEntity enterpriseEvaluate){
        enterpriseEvaluate.setUpdateTime(new Date());
        enterpriseEvaluate.setUpdateUserId(getUserId());
        enterpriseEvaluate.setUpdateUserName(getUserName());
		enterpriseEvaluateService.updateById(enterpriseEvaluate);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ApiOperation("删除")
    public R delete(@RequestBody Integer[] ids){
		enterpriseEvaluateService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
